var quickNavigation = require("./../../../components/quick-navigation/quick-navigation.js"), interval = 0, page_first_init = !0, timer = 1, fullScreen = !1;

Page({
  data: {
    // 领取状态 假数据
    receiveType: 0, //0 表示尚未领取   1  表示已经领取了
    id:"my",
  },
  // 领取礼品卡
  toReceiveBtn: function(e) {
    console.log(e)
    let that = this    
    let receiveType = that.data.receiveType
    if (receiveType == 1) {
      wx.showModal({
        title: '对不起',
        content: '本张礼品卡已经领取过了！',
        showCancel: true,
        cancelText: '再转转',
        confirmText: '知道了',
        success: function(res) {
          console.log(res)
          if (res.confirm == true) {
            wx.redirectTo({
              url: '/pages/index/index',
            })
          } else {
            
            wx.redirectTo({
              url: '/pages/card_package/index',
            })
          }
        }
      })
    } else {
      // 领取成功后 改变当前状态值 后期需要后台返回状态字
      that.setData({
        receiveType: 1
      })
      // 展示领取状态
      wx.showModal({
        title: '领取',
        content: '好友送您的礼品卡已经到账咯！',
        showCancel: true,
        cancelText: '知道了',
        confirmText: '去看看',
        success: function(res) {
          console.log(res)
          if (res.confirm == true) {
            wx.redirectTo({
              url: '/pages/card_package/index?backIndex=0',                            
            })
          } else {
            wx.redirectTo({
              url: '/pages/index/index',
            })
          }
        }
      })
    }
  },
  // 卡片的详情接口
  theCard:function(){
    console.log("调用了卡片详情的接口")
  },
  onLoad: function(t) {
    console.log(t)
    
    this.theCard()

    // 判断是否已经授权
    getApp().page.onLoad(this, t),  quickNavigation.init(this);
    let that = this

    // share_gift_card
    getApp().request({
      url: getApp().api.cardshop.share_gift_card,
      data: {
        buy_id: t.buy_id
      },
      success: function (t) {
        console.log(t)        
        that.setData({
          details:t.data
        })

      }
    });
  },
  // 领取加油卡   share_receive_gift_cards
  getTheCard(){
    let that = this
    getApp().request({
      url: getApp().api.cardshop.share_receive_gift_cards,
      data: {
        buy_id: that.data.details.id,
        give_user_id: that.data.details.user_id
      },
      success: function (t) {
        console.log(t)
        console.log("领取加油卡信息打印")
        if(t.code== 0 ){
          wx.showModal({
            title: '您好',
            content:'您已经成功领取' + that.data.details.nickname + '送您的礼品卡',
            showCancel: true,
            cancelText: '去首页',          
            confirmText: '去看看',            
            success: function(res) {
              if (res.confirm == true) {
                wx.redirectTo({
                  url: '/pages/card_package/index',
                })
              } else {
                wx.redirectTo({
                  url: '/pages/index/index',
                })
              }
            }
          })
        }else {
          wx.showModal({
            title: '您好',
            content: t.msg,
            showCancel: true,
            cancelText: '去首页',
            confirmText: '去看看',
            success: function (res) {
              if (res.confirm == true) {
                wx.redirectTo({
                  url: '/pages/card_package/index',
                })
              } else {
                wx.redirectTo({
                  url: '/pages/index/index',
                })
              }
            }
          })
        }
      }
    });       
  },
  onReady: function() {

  },
  onShow: function() {

  },
  onHide: function() {

  },
  onUnload: function() {

  },
  onPullDownRefresh: function() {

  },
  onReachBottom: function() {

  },
  // 分享本页面  测试领取状态值
  onShareAppMessage: function() {
    return {
      title: '分享给我的好友',
      
      path: 'pages/card_voucher/share/share?id=' + this.data.id,
      success: function (res) {
        console.log(res)
      }
    }
  }
})